To showcase the capabilities of ggplot2, a popular data visualization library in R, by using the penguins and diamonds datasets to create a variety of plots that demonstrate the different functions available in the library.
The penguins dataset contains information on the size and species of penguins, while the diamonds dataset contains information on the price, carat weight, and other features of diamonds. Both datasets will be used to demonstrate the different plotting functions available in ggplot2.
The project demonstrates the flexibility and power of ggplot2 as a data visualization tool in R. The use of both the penguins and diamonds datasets allowed for the creation of a variety of plots that showcased the different functions available in the library, such as histograms, bar plots, scatter plots, and more. The results of the project highlight the effectiveness of ggplot2 for data visualization and the ease with which plots can be created and customized.
library("ggplot2")
library("palmerpenguins")
data("penguins")
View(penguins)
can also add captions to the plot –‘soooo cool :)!’
ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g))
ggplot(data = penguins, mapping = aes(x = flipper_length_mm, y = body_mass_g)) +
geom_point()
ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, shape = species))
ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, shape = species, color = species))
ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, shape = species, color = species, size = species))
ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, alpha = species))
ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g), color = "purple")
ggplot(data = penguins) +
geom_smooth(mapping = aes(x = flipper_length_mm, y = body_mass_g))
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
ggplot(data = penguins) +
geom_smooth(mapping = aes(x = flipper_length_mm, y = body_mass_g)) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g))
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
ggplot(data = penguins) +
geom_smooth(mapping = aes(x = flipper_length_mm, y = body_mass_g, linetype = species))
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
ggplot(data = penguins) +
geom_jitter(mapping = aes(x = flipper_length_mm, y = body_mass_g))
ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, color = species)) +
facet_grid(sex ~ species)
ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, color = species)) +
facet_wrap(~species)
data("diamonds")
View(diamonds)
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut))
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, color = cut))
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, fill = cut))
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, fill = clarity))
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = color, fill = cut)) +
facet_wrap(~cut)
ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, color = species)) +
labs(title = "Palmer Penguins: Body Mass vs. Flipper Length")
ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, color = species)) +
labs(title = "Palmer Penguins: Body Mass vs. Flipper Length", subtitle = "Sample of Three Penguins Species")
ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, color = species)) +
labs(title = "Palmer Penguins: Body Mass vs. Flipper Length", subtitle = "Sample of Three Penguins Species", caption = "Data collected by Dr. Kristen Gorman")
ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, color = species)) +
labs(title = "Palmer Penguins: Body Mass vs. Flipper Length", subtitle = "Sample of Three Penguins Species", caption = "Data collected by Dr. Kristen Gorman") +
annotate("text",x=220, y=3500, label= "The Gentoos are the largest" )
ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, color = species)) +
labs(title = "Palmer Penguins: Body Mass vs. Flipper Length", subtitle = "Sample of Three Penguins Species", caption = "Data collected by Dr. Kristen Gorman") +
annotate("text",x=220, y=3500, label= "The Gentoos are the largest", color="purple" )
ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, color = species)) +
labs(title = "Palmer Penguins: Body Mass vs. Flipper Length", subtitle = "Sample of Three Penguins Species", caption = "Data collected by Dr. Kristen Gorman") +
annotate("text",x=220, y=3500, label= "The Gentoos are the largest", color="purple", fontface="bold", size=4.5 )
ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, color = species)) +
labs(title = "Palmer Penguins: Body Mass vs. Flipper Length", subtitle = "Sample of Three Penguins Species", caption = "Data collected by Dr. Kristen Gorman") +
annotate("text",x=220, y=3500, label= "The Gentoos are the largest", color="purple", fontface="bold", size=4.5, angle=25 )
p <- ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, color = species)) +
labs(title = "Palmer Penguins: Body Mass vs. Flipper Length", subtitle = "Sample of Three Penguins Species", caption = "Data collected by Dr. Kristen Gorman")
p + annotate("text",x=220, y=3500, label= "The Gentoos are the largest", color="purple", fontface="bold", size=4.5, angle=25 )